package cn.weakup.optional;

import java.util.Optional;

/**
 * @author Dawn
 * @version 1.0.0
 * @desc
 * @date 2022/5/14
 */
public class OptionalTest {

    public static void main(String[] args) {
        String name = "Dawn";
        Optional<String> opt = Optional.of(name);
        assertEquals("Optional[Dawn]", opt.toString());
        System.out.println(opt.isPresent());
        opt.ifPresent(str -> System.out.println(str.length()));


        String name2 = null;
        Optional<String> opt2 = Optional.ofNullable(name2);
        System.out.println(opt2.isPresent());
        opt2.ifPresent(str -> System.out.println(str.length()));
        System.out.println(Optional.ofNullable(name2).orElse("Default"));
    }


    private static void assertEquals(String s, String toString) {
        System.out.println(s.equals(toString));
    }
}
